import cookie from 'js-cookie'
import { baseuserinfo, cutEnd } from "@api/cutPrice";
import cbct from "@common/base.js";
export default {
  namespaced:true,
  state:{
    cutUid:cookie.get('cutUid') || '',
    avatar:cbct.imgUrl()+'default_head.png',
    isEnd:0,// 活动是否结束
    shop_number:''
  },
  mutations:{
    SET_INFO(state,info){
      cookie.set('cutUid',info.uid,{expires:365})
      state.cutUid = info.uid
      state.avatar = `${cbct.imgUrl()}${info.avatar}`
    },
    END(state,info){
      state.isEnd = info.is_over
      state.shop_number = info.shop_number
    }
  },
  actions:{
    userInfo({commit}){
      return baseuserinfo().then(res => {
        commit('SET_INFO',res.data)
        return res.data
      });
    },
    isEnd({commit}){
      cutEnd().then(res =>{
        commit('END',res.data)
      })
    }

  }
}